
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sai.mysql.DriverLoading;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author sai
 */
public class Search extends HttpServlet {

    String deptid, docname, gender, email, mobile, qual, deptname;
    String deptid1,docname1, gender1, email1, mobile1, qual1;

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String name = req.getParameter("docname");      
        String dept=req.getParameter("dept");
        String location=req.getParameter("location");
        try {
            DriverLoading dl = new DriverLoading();
            Statement st = dl.getStatement();
            Statement st1 = dl.getStatement();
            Statement st2 = dl.getStatement();
            Statement st3 = dl.getStatement();
            if (name != null) {                
                String url = "select dept_id,doctor_name,gender,email,mobile,max_qualification from `doctor` where doctor_name='" + name + "'";
                ResultSet rs = st.executeQuery(url);
                if (rs.next()) {
                    deptid = rs.getString(1);
                    docname = rs.getString(2);
                    gender = rs.getString(3);
                    email = rs.getString(4);
                    mobile = rs.getString(5);
                    qual = rs.getString(6);                   
                } else {
                    out.print("<center><h1>search again</h1></center>");
                    out.print("<a href='search.html'>click here</a>");
                }
                if (deptid != null) {                    
                    String url1 = "select dept_name from `department` where dept_id='" + deptid + "'";
                    ResultSet rs1 = st1.executeQuery(url1);
                    if (rs1.next()) {
                        deptname = rs1.getString(1);                       
                    } else {
                        out.print("<center><h1>search again</h1></center>");
                        out.print("<a href='search.html'>click here</a>");
                    }
                     
                    out.print("<a href=search.jsp?docname=" + docname + "&gender=" + gender + "&email=" + email + "&mobile=" + mobile + "&qual=" + qual + "&deptname=" + deptname + ">");
                    out.print("Doctor Name=" + docname + " And    department=" + deptname + "And   email=" + email + "And   qualification=" + qual);
                    out.print("</a><br><br>");
                    out.println();
                }
                
                if(dept!=null)
                {
                    String url1 = "select dept_id from `department` where dept_name='" + dept + "'";
                    ResultSet rs2 = st2.executeQuery(url1);
                    if (rs2.next()) {
                        deptid1 = rs2.getString(1);                       
                    } else {
                        out.print("<center><h1>search again</h1></center>");
                        out.print("<a href='search.html'>click here</a>");
                    }                   
                               
                String url2 = "select doctor_name,gender,email,mobile,max_qualification from `doctor` where dept_id='" + deptid1 + "'";
                ResultSet rs3 = st3.executeQuery(url2);
                if (rs3.next()) {                   
                    docname1 = rs3.getString(1);
                    gender1 = rs3.getString(2);
                    email1 = rs3.getString(3);
                    mobile1 = rs3.getString(4);
                    qual1 = rs3.getString(5);                   
                } else {
                    out.print("<center><h1>search again</h1></center>");
                    out.print("<a href='search.html'>click here</a>");
                }
                    out.print("<a href=search.jsp?docname=" + docname1 + "&gender=" + gender1 + "&email=" + email1 + "&mobile=" + mobile1 + "&qual=" + qual1 + "&deptname=" + dept + ">");
                    out.print("Doctor Name=" + docname1 + "And     department=" + dept + " And   email=" + email1 + "  And  qualification=" + qual1);
                    out.print("</a><br><br>");
                    out.println();
                }
            }
        } catch (Exception e) {
            out.println(e);
        }

    }
}
